<?php

namespace app\index\controller;

use think\Db;
use think\Cache;
class Qian extends Common{
	public function index(){
		 
		$vendor = $this->gCache('redis','vendor','vendor', 'domain,accessKeyId');
		$this->assign('ad_url',$this->getAd());
		//$this->assign('vendor','http://'.md5(time().'vendor').'.'.$vendor['domain'].'/chouyao.p'.createrand(3).'html?words='.createrand(5).'&id='.mt_rand(1,20));
		//$this->assign('vendor','http://my168.'.$vendor['domain'].'/chouyao.html?id='.mt_rand(1,20));
		//$this->assign('vendor','http://my168.'.$vendor['domain'].'/chouyao.html?words='.createrand(5).'&id='.mt_rand(1,20));
		//$this->assign('vendor','http://'.md5(time().'vendor').'.'.$vendor['domain'].'/chouyao.html?id='.mt_rand(1,20));
		$this->assign('vendor','http://my168.'.$vendor['domain'].'/chouyao.p'.createrand(3).'html?words='.createrand(5).'&id='.mt_rand(1,20));
		return $this->fetch();
	}
	public function qian($id){
		$qid=$id;
		if(!$jump = cache::store('redis')->get('jump')){
            $jump=Db::name('jump')->where('status',2)->field('domain,appid')->select();
            cache::store('redis')->set('jump',$jump,600);
		}
		shuffle($jump);
        //$imp = 'http://'.createrand(4).'.'.$jump[0]['domain'].'/goto/'.$qid.'/'.createrand(12).'?code='.createrand(5);
        $imp = 'http://'.$jump[0]['domain'].'/goto/'.$qid.'/'.createrand(12).'?code='.createrand(5);
		$data = $this->Dlist($qid);
		$data['timeline'] = array(
				'title'=>'我的命竟是：'.$data['name'],
				//'title'=>'我的命竟是1234',
				// 'link'=>'http://ptlogin.qq.com/jump?u1='.urlencode('https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$jump[0]['appid'].'&redirect_uri='.$imp.'?n=lastkey&t=1528158837&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'),
                'link'=>$imp,
				'link2'=>'http://sax4.okyes.cn/click?type=nonstd&t=REowMDAxNjEzNQ==&sign=&url='.urlencode($imp[0]),
			);
		$arrive = $this->gCache('redis', 'arrive', 'arrive','domain');
		//$data['url'] = 'http://'.md5(time().'arrive').'.'.$arrive['domain'].'/news/content/'.$qid.'/'.createrand(5);
		 $data['url'] = 'http://xi.'.$arrive['domain'].'/news/content/'.$qid.'/'.createrand(5);
		$data['ad_url'] = $this->getAd();
		$this->assign('data', $data);
		return $this->fetch('qian');
	}
	public function gCache($type, $name, $table, $zduan){
		if(!$data = cache::store($type)->get($name)){
            $data=Db::name($table)->where('status',2)->field($zduan)->find();
            cache::store($type)->set($name,$data,600);
		}
		return $data;
	}
	public function getAd(){
		if(!$ad = cache::store('redis')->get('jeff_ad')){
            $ad=Db::name('ad')->where('status',2)->field('domain')->find();
            cache::store('redis')->set('jeff_ad',$ad,120);
		}
		return $ad['domain'];
	}
	public function jump($qid){
		//$arrive = $this->gCache('redis', 'arrive', 'arrive','domain');
        if(!$arrive = cache::store('redis')->get('arrive')){
            $arrive=Db::name('arrive')->where('status',2)->field('domain')->find();
            cache::store('redis')->set('arrive',$arrive,600);
        }
		// $url= 'http://'.md5(time().'tts').'.'.$arrive['domain'].'/news/content/'.$qid.'/'.createrand(5).'?flag=6';
		$url = 'http://xi.'.$arrive['domain'].'/news/content/'.$qid.'/'.createrand(5).'?flag=6';
        //$url[1] = 'http://wx.ksjx168.com./qian/res/'.$qid;
        //shuffle($url);
        header("Location:".$url);
        exit;
        // $this->assign('url',$url);
        // return $this->fetch('jump');
	}

	public function res($qid,$flag=9){
		if($qid>21){
            $qid =mt_rand(1,20);
        }
		$data=$this->Dlist($qid);
        if(empty($data)){
            exit('error');
        }
		if(!$arrive = cache::store('redis')->get('arrive')){
            $arrive=Db::name('arrive')->where('status',2)->field('domain')->find();
            cache::store('redis')->set('arrive',$arrive,600);
        }
		 //$data['url']='http://'.md5(time().'tts').'.'.$arrive['domain'];
		$data['url']='http://xi.'.$arrive['domain'];
		if($flag===9){
			$data['flag'] = true;
		}else{
			$data['flag'] = false;
		}
		$data['date'] = date('Y-m-d');
		$data['ad_url'] = $this->getAd();
		$this->assign('data', $data);
		return $this->fetch('res');
	}
    public function Dlist($id){
        $list = [
            ['name'=>'【人中龙凤】7两3钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01uIWYGx2IibqQO8F2E_!!468199320.jpg'],
            ['name'=>'【福禄双全】6两7钱','pic'=>'https://img.alicdn.com/imgextra/i4/468199320/O1CN01yI3P1K2IibqVHY5AL_!!468199320.jpg'],
            ['name'=>'【衣食无忧】6两9钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01B1tP9i2IibqSuXtMi_!!468199320.jpg'],
            ['name'=>'【逍遥快活】5两7钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01Iyv97O2IibqRW4K4p_!!468199320.jpg'],
            ['name'=>'【升官发财】6两3钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01XiaJoI2IibqTmykJd_!!468199320.jpg'],
            ['name'=>'【衣锦还乡】5两1钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01rrWHYf2IibqVHXHEz_!!468199320.jpg'],
            ['name'=>'【苦尽甘来】5两3钱','pic'=>'https://img.alicdn.com/imgextra/i3/468199320/O1CN01HqWR132IibqVHYosZ_!!468199320.jpg'],
            ['name'=>'【大器晚成】4两7钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN016wuh032IibqQO8RSY_!!468199320.jpg'],
            ['name'=>'【白手起家】4两3钱','pic'=>'https://img.alicdn.com/imgextra/i4/468199320/O1CN01xtqDfT2IibqLsLS8O_!!468199320.jpg'],
			['name'=>'【四海为家】3两6钱','pic'=>'https://img.alicdn.com/imgextra/i4/468199320/O1CN01udjxFJ2IibqSuYlJv_!!468199320.jpg'],
			['name'=>'【光宗耀祖】4两9钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01Z3R10C2IibqSxqq6L_!!468199320.jpg'],
			['name'=>'【命犯桃花】3两3钱','pic'=>'https://img.alicdn.com/imgextra/i1/468199320/O1CN01Jwtj9c2IibqRW37Ch_!!468199320.jpg'],
			['name'=>'【六亲无靠】4两8钱','pic'=>'https://img.alicdn.com/imgextra/i1/468199320/O1CN01pqsdxt2IibqVHW8Wi_!!468199320.jpg'],
			['name'=>'【三起三落】5两4钱','pic'=>'https://img.alicdn.com/imgextra/i3/468199320/O1CN01Y07Dy92IibqTvN2em_!!468199320.jpg'],
			['name'=>'【生财有道】6两4钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01fFUbEX2IibqQO8yjr_!!468199320.jpg'],
			['name'=>'【纸醉金迷】5两7钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01Iyv97O2IibqRW4K4p_!!468199320.jpg'],
			['name'=>'【挥金如土】6两8钱','pic'=>'https://img.alicdn.com/imgextra/i3/468199320/O1CN014EIkBZ2IibqTvNVlg_!!468199320.jpg'],
			['name'=>'【生财有道】6两4钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01fFUbEX2IibqQO8yjr_!!468199320.jpg'],
			['name'=>'【逍遥快活】5两7钱','pic'=>'https://img.alicdn.com/imgextra/i2/468199320/O1CN01Iyv97O2IibqRW4K4p_!!468199320.jpg'],
			['name'=>'【家财万贯】6两8钱','pic'=>'https://img.alicdn.com/imgextra/i3/468199320/O1CN014EIkBZ2IibqTvNVlg_!!468199320.jpg'],
        ];
        return $list[$id-1];
    }
	
}
